//
//  XDUnitCementSelectCourseViewController.m
//  XDEducation
//
//  Created by apple on 2017/4/15.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "XDUnitCementSelectCourseViewController.h"
#import "XDUnitCementSelectCourseHeaderView.h"
#import "XDUnitCementVersionsModel.h"
#import "XDUnitCementSubjectModel.h"
#import "XDUnitCementGradeModel.h"
#import "XDUnitCementUnitModel.h"
#import "XDUnitCementTeacherModel.h"
#import "XDUnitCementListModel.h"
#import "XDSingleBtnCell.h"
#import "XDUnitCementListViewController.h"
@interface XDUnitCementSelectCourseViewController ()

/** 页面数据源 */
@property(nonatomic,strong) NSArray *defaultDataArr;

/** 下一步按钮 */
@property(nonatomic,strong) UIButton *nextButton;

#pragma mark - 数据源  页面显示数据
/** 年级 */
@property(nonatomic,strong) NSArray *gradeArr;

/** 版本号 */
@property(nonatomic,strong) NSArray *versonsArr;

/** 科目 */
@property(nonatomic,strong) NSMutableArray *subjectsArr;

/** 学期 */
@property(nonatomic,strong) NSArray *termArr;

/** 单元 */
@property(nonatomic,strong) NSMutableArray *unitArr;

/** 教师 */
@property(nonatomic,strong) NSMutableArray *teacherArr;

#pragma mark - 网络请求数据

/** 年级 */
@property(nonatomic,strong) NSMutableArray *gradesModelArr;
/** 版本 */
@property(nonatomic,strong) NSMutableArray *versonsModelArr;
/** 科目 */
@property(nonatomic,strong) NSMutableArray *subjectsModelArr;
/** 单元 */
@property(nonatomic,strong) NSMutableArray *unitModelArr;
/** 教师 */
@property(nonatomic,strong) NSMutableArray *teacherModelArr;

/** 课程列表内容 */
@property(nonatomic,strong) NSMutableArray *unitCementListModelArr;


/** tableView headerView */
@property(nonatomic,strong)  XDUnitCementSelectCourseHeaderView *headerView;
/** 列表打开状态 */
@property(nonatomic,assign) BOOL cellOpenStatus;



@property(nonatomic,copy)NSString *selectedGrade;  //选中的年级
@property(nonatomic,copy)NSString *selectedVerson;  //选中的版本
@property(nonatomic,copy)NSString *selectedSubject;  //选中的年级
@property(nonatomic,copy)NSString *selectedTerm;  //选中的学期
@property(nonatomic,copy)NSString *selectedUnit;  //选中的单元
@property(nonatomic,copy)NSString *selectedTeacher;  //选中的教师

#pragma mark - 请求参数
@property(nonatomic,strong)NSNumber *selectedGradelId;  //选中的年级id
@property(nonatomic,strong)NSNumber *selectedVersonId;  //选中的版本id
@property(nonatomic,strong)NSNumber *selectedSubjectId;  //选中的年级id
@property(nonatomic,strong)NSNumber *selectedTermId;  //选中的学期id
@property(nonatomic,strong)NSNumber *selectedUnitId;  //选中的单元id
@property(nonatomic,strong)NSNumber *selectedTeacherId;  //选中的教师id


@end

static NSString *const cellId = @"SelectCourseCell";

/*
 \  若当前页面是期中期末巩固  \
 */


@implementation XDUnitCementSelectCourseViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    
    [self.view addSubview:self.nextButton];
    //[self initNormalRefreshHeaderView];
    [self initNetworkingWithRefreshStatus:RefreshStatePullDown];
    
}


#pragma mark - 懒加载
-(NSArray *)defaultDataArr{

    if (!_defaultDataArr) {
        
        NSDictionary *dict;
        
        if (self.selectCourseType == SelectCourseTypeUnitCement) {
            dict = @{@"title":@"单元:",@"subtitle":@"请选择单元"};
        }else{
            dict = @{@"title":@"阶段:",@"subtitle":@"请选择阶段"};
        }
        
        _defaultDataArr = [NSArray arrayWithObjects:
                        @{@"title":@"年级:",@"subtitle":@"请选择年级"},
                        @{@"title":@"版本:",@"subtitle":@"请选择版本"},
                        @{@"title":@"科目:",@"subtitle":@"请选择科目"},
                        @{@"title":@"学期:",@"subtitle":@"请选择学期"},
                        dict,
                        @{@"title":@"老师:",@"subtitle":@"请选择老师"},
                        nil];
    }
    return _defaultDataArr;
}

-(NSArray *)gradeArr{

    if (!_gradeArr) {
        _gradeArr = [NSArray array];
    }
    return _gradeArr;
}
-(NSMutableArray *)versonsModelArr{
    
    if (!_versonsModelArr) {
        _versonsModelArr = [NSMutableArray array];
    }
    return _versonsModelArr;
}

-(NSArray *)versonsArr{
    if(!_versonsArr){
        _versonsArr = [NSMutableArray array];
    }
    return _versonsArr;
}
-(NSArray *)termArr{
    if (_termArr == nil) {
        _termArr = [NSArray array];
    }
    return _termArr;
}

-(NSMutableArray *)subjectsArr{
    
    if (!_subjectsArr) {
        _subjectsArr = [NSMutableArray array];
    }
    return _subjectsArr;
}

-(NSMutableArray *)subjectsModelArr{
    if (!_subjectsModelArr) {
        _subjectsModelArr = [NSMutableArray array];
    }
    return _subjectsModelArr;
}

-(NSMutableArray *)gradesModelArr{

    if (!_gradesModelArr) {
        _gradesModelArr = [NSMutableArray array];
    }
    return _gradesModelArr;
}

-(NSMutableArray *)unitModelArr{
    if (!_unitModelArr) {
        
        _unitModelArr = [NSMutableArray array];
    }
    return _unitModelArr;
}

-(NSMutableArray *)unitArr{
    if (!_unitArr) {
        _unitArr = [NSMutableArray array];
    }
    return _unitArr;
}
-(NSMutableArray *)teacherArr{

    if (!_teacherArr) {
        _teacherArr = [NSMutableArray array];
    }
    return _teacherArr;
}


-(NSMutableArray *)teacherModelArr{
    if (!_teacherModelArr) {
        _teacherModelArr = [NSMutableArray array];
    }
    return _teacherModelArr;
}

-(NSMutableArray *)unitCementListModelArr{
    
    if (!_unitCementListModelArr) {
        _unitCementListModelArr = [NSMutableArray array];
    }
    return _unitCementListModelArr;
}

-(NSArray*)getTermData{
    
    NSArray *array = [NSArray arrayWithObjects:
                           @"上学期",
                           @"下学期",
                           nil];
    return array;
}

-(NSMutableArray *)getTestMoment{
    
    NSMutableArray *array = [NSMutableArray arrayWithObjects:
                           @"期中",
                           @"期末",
                           nil];
    return array;

}

#pragma mark - tableview delegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.defaultDataArr.count + 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    switch (section) {
        case 0:
            return self.gradeArr.count;
            break;
        case 1:
            return self.versonsArr.count;
            break;
        case 2:
            return self.subjectsArr.count;
            break;
        case 3:
            return self.termArr.count;
            break;
        case 4:
            return self.unitArr.count;
            break;
        case 5:
            return self.teacherArr.count;
            break;
        case 6:
            return 1;
            break;
        default:
            return 0;
            break;
    }
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{

    if (section == 6) return 0;
    return 50 * ScaleHeight;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{

    NSDictionary *dict = self.defaultDataArr[section];
    WeakSelf(weakself)
    _headerView = [[XDUnitCementSelectCourseHeaderView alloc]init];
    _headerView.title = dict[@"title"];
    
    switch (section) {
        case 0:{
            if (_selectedGrade == nil) {
                _headerView.subTitle  = dict[@"subtitle"];
            }else{
                _headerView.subTitle  = _selectedGrade;
            }
        }
            break;
        case 1:{
            if (_selectedVerson == nil) {
                _headerView.subTitle  = dict[@"subtitle"];
            }else{
                _headerView.subTitle  = _selectedVerson;
            }
        }
            break;
        case 2:{
            if (_selectedSubject == nil) {
                _headerView.subTitle  = dict[@"subtitle"];
            }else{
                _headerView.subTitle  = _selectedSubject;
            }
        }
            break;
        case 3:{
            if (_selectedTerm == nil) {
                _headerView.subTitle  = dict[@"subtitle"];
            }else{
                _headerView.subTitle  = _selectedTerm;
            }
        }
            break;
        case 4:{
            if (_selectedUnit == nil) {
                _headerView.subTitle  = dict[@"subtitle"];
            }else{
                _headerView.subTitle  = _selectedUnit;
            }
        }
            break;
        case 5:{
            if (_selectedTeacher == nil) {
                _headerView.subTitle  = dict[@"subtitle"];
            }else{
                _headerView.subTitle  = _selectedTeacher;
            }
        }
            break;
        default:
            break;
    }
    
    
    _headerView.isOpen = _cellOpenStatus;
    _headerView.headerViewClickedBlock = ^(BOOL selectedStatus){
        
        switch (section) {
            case 0:{            //年级
                
                if (selectedStatus) {       //打开列表
                    weakself.gradeArr = weakself.gradesModelArr;
                    weakself.cellOpenStatus = YES;
                    [weakself.tableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:UITableViewRowAnimationFade];
                    
                }else{                      //关闭列表
                    weakself.gradeArr = nil;
                    weakself.cellOpenStatus = NO;
                    [weakself.tableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:UITableViewRowAnimationFade];
                    
                }
                
            }
                break;
            case 1:{   //版本号
                
                if (selectedStatus) {       //打开列表
                    weakself.versonsArr = weakself.versonsModelArr;
                    weakself.cellOpenStatus = YES;
                    [weakself.tableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:UITableViewRowAnimationFade];
                    
                }else{                      //关闭列表
                    weakself.versonsArr = nil;
                    weakself.cellOpenStatus = NO;
                    [weakself.tableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:UITableViewRowAnimationFade];
                    
                }
                
            }
                break;
            case 2:{    //年级
                
                if (selectedStatus) {       //打开列表
                    weakself.subjectsArr = weakself.subjectsModelArr;
                    weakself.cellOpenStatus = YES;
                    [weakself.tableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:UITableViewRowAnimationFade];
                    
                }else{                      //关闭列表
                    weakself.subjectsArr = nil;
                    weakself.cellOpenStatus = NO;
                    [weakself.tableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:UITableViewRowAnimationFade];
                    
                }
                
            
            }
                break;
            case 3:{    //学期
                if (selectedStatus) {       //打开列表
                    weakself.termArr = [weakself getTermData];
                    weakself.cellOpenStatus = YES;
                    [weakself.tableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:UITableViewRowAnimationFade];
                    
                }else{                      //关闭列表
                    weakself.termArr = nil;
                    weakself.cellOpenStatus = NO;
                    [weakself.tableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:UITableViewRowAnimationFade];
                    
                }
            }
                break;
                
                
                
            case 4:{    //单元        \期中期末
                
                if(weakself.selectCourseType == SelectCourseTypeUnitCement){    //单元巩固
                    
                    [weakself getUnitNetWorkRequestWithSection:section selectedStatus:selectedStatus];
                }else{      //期中期末巩固
                    
                    if (selectedStatus) {       //打开列表
                        weakself.unitArr = [weakself getTestMoment];
                        weakself.cellOpenStatus = YES;
                        [weakself.tableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:UITableViewRowAnimationFade];
                        
                    }else{                      //关闭列表
                        
                        weakself.unitArr = nil;
                        weakself.cellOpenStatus = NO;
                        [weakself.tableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:UITableViewRowAnimationFade];
                        
                    }
                }
            }
                break;
            case 5:{     //老师
                if(self.selectCourseType == SelectCourseTypeUnitCement){
                
                    [weakself getUnitCementTeachersNetWorkRequest:section selectedStatus:selectedStatus];
                }else{
                    
                    [weakself getTermCementTeachersNetWorkRequest:section selectedStatus:selectedStatus];
                
                }
            }
                break;
                
            default:
                break;
        }

    };
    return _headerView;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if(indexPath.section == 6) return 70 * ScaleHeight;
    return 40 * ScaleHeight;
    
    
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (!cell) {
        cell =[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.textLabel.textColor =  ThemeColor; //UIColorFromRGB(0x4c4c4c);
    cell.textLabel.font = [UIFont systemFontOfSize:14];
    switch (indexPath.section) {
        case 0:{
            XDUnitCementGradeModel *model = self.gradeArr[indexPath.row];
            cell.textLabel.text = model.gradename;
        }
            break;
        case 1:{
            XDUnitCementVersionsModel *model = self.versonsArr[indexPath.row];
            cell.textLabel.text = model.textbookname;
        }
            break;
        case 2:{
            XDUnitCementSubjectModel *model = self.subjectsArr[indexPath.row];
            cell.textLabel.text = model.subjectname;
        }
            break;
        case 3:{
            cell.textLabel.text = self.termArr[indexPath.row];
        }
            break;
        case 4:{
            
            if (self.selectCourseType == SelectCourseTypeUnitCement) {
                XDUnitCementUnitModel *model = self.unitArr[indexPath.row];
                cell.textLabel.text = model.unit_name;
            }else{
                 cell.textLabel.text = self.unitArr[indexPath.row];
            }
            
        }
            break;
        case 5:{
            XDUnitCementTeacherModel *model = self.teacherArr[indexPath.row];
            cell.textLabel.text = model.realName;
        }
            break;
        case 6:{
            XDSingleBtnCell *cell =  [XDSingleBtnCell cellWithTableView:tableView];
            cell.separatorInset = UIEdgeInsetsMake(0, ScreenW, 0, 0);
            WeakSelf(weakself)
            cell.buttonClickedBlock = ^(){      //下一步点击事
                if (weakself.selectCourseType == SelectCourseTypeUnitCement) {
                    [weakself getUnitCementListNetWorkRequest];
                }else{
                    [weakself getTermCementListNetWorkRequest];
                }
                
            };
            return cell;
        }
        default:
            break;
    }
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    switch (indexPath.section) {
        case 0:{     //年级
            XDUnitCementGradeModel *model = self.gradesModelArr[indexPath.row];
            _selectedGrade = model.gradename;
            _selectedGradelId = model.gradeid;
            self.gradeArr = nil;

        }
            break;
            
        case 1:{    //版本号
            XDUnitCementVersionsModel *model = self.versonsArr[indexPath.row];
           _selectedVerson = model.textbookname;
            _selectedVersonId = model.tid;
            self.versonsArr = nil;
         
        }
            break;
        case 2:{    //课程名
            
            XDUnitCementSubjectModel *model = self.subjectsArr[indexPath.row];
            _selectedSubject = model.subjectname;
            _selectedSubjectId = model.subjectid;
            self.subjectsArr = nil;
        }
            break;
        case 3:{    //学期
            
            _selectedTerm = self.termArr[indexPath.row];
            if ([_selectedTerm isEqualToString:@"上学期"]) {
                _selectedTermId = @1;
            }else if ([_selectedTerm isEqualToString:@"下学期"]){
                _selectedTermId = @2;
            }
            self.termArr = nil;
        }
            break;
        case 4:{    //单元   ||  期中期末
            
            if(self.selectCourseType == SelectCourseTypeUnitCement){
                
                XDUnitCementUnitModel *model = self.unitArr[indexPath.row];
                _selectedUnit = model.unit_name;
                _selectedUnitId = model.ID;
                self.unitArr = nil;
                
            }else{
                
                _selectedUnit = self.unitArr[indexPath.row];
                if ([_selectedUnit isEqualToString:@"期中"]) {
                    _selectedUnitId = @1;
                }else if ([_selectedTerm isEqualToString:@"期末"]){
                    _selectedUnitId = @0;
                }
                self.unitArr = nil;
            
            }
        }
            break;
        case 5:{    //教师
            XDUnitCementTeacherModel *model = self.teacherArr[indexPath.row];
            _selectedTeacher = model.realName;
            _selectedTeacherId = model.uid;
            self.teacherArr = nil;
        }
            break;
        default:
            break;
    }

    self.cellOpenStatus = NO;
    [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationFade];
}


-(void)initNetworkingWithRefreshStatus:(RefreshState)status{
    
    NSString *url = BaseURL(@"consolidate.do?action=getSelectableInfo");

    [MBProgressHUD showHUD];
    
    [XDHttpTool get:url authCode:[AccountTool shareAccountTool].currentAccount.authCode params:nil success:^(id responseObj) {
        
        [MBProgressHUD hideHUD];
        //NSLog(@"%@",responseObj);
        
        NSDictionary *dict = [responseObj objectForKey:@"t"];
 
        
        NSArray *gradesDictArr = [dict objectForKey:@"grades"];
        NSMutableArray *gradeModelArr = [XDUnitCementGradeModel mj_objectArrayWithKeyValuesArray:gradesDictArr];
        self.gradesModelArr = gradeModelArr;
        
        //科目
        NSArray *subjectsDictArr = [dict objectForKey:@"subjects"];
        NSMutableArray *subjectModelArr = [XDUnitCementSubjectModel mj_objectArrayWithKeyValuesArray:subjectsDictArr];
        self.subjectsModelArr = subjectModelArr;
        
        
        
        //版本
        NSArray *textBooksDictArr = [dict objectForKey:@"textBooks"];
        NSMutableArray *textBooksModelArr = [XDUnitCementVersionsModel mj_objectArrayWithKeyValuesArray:textBooksDictArr];
        self.versonsModelArr = textBooksModelArr;
        
        
    } failure:^(NSError *error) {
        
        NSLog(@"%@",error);
        [MBProgressHUD hideHUD];
        [MBProgressHUD showError:XDNetWorkError];
    }];

}


/**
 获取单元列表
 */
-(void)getUnitNetWorkRequestWithSection:(NSInteger)section selectedStatus:(BOOL)status{

    
    
    if (_selectedGradelId == 0) {
        [MBProgressHUD showError:@"请选择年级"];
        return;
    }
    
    if (_selectedSubjectId == 0) {
        [MBProgressHUD showError:@"请选择版本"];
        return;
    }
    if (_selectedTermId == 0) {
        [MBProgressHUD showError:@"请选择学期"];
        return;
    }
    
    if (_selectedSubjectId == 0) {
        [MBProgressHUD showError:@"请选择课程"];
        return;
    }
    
    
    if(!status){                      //关闭列表
        self.unitArr = nil;
        self.cellOpenStatus = NO;
        [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:UITableViewRowAnimationFade];
        return;
    }

    
    NSString *url = BaseURL(@"consolidate.do?action=getUnits");

    NSDictionary *dict = @{@"termType":_selectedTermId,
                          @"subjectid":_selectedSubjectId,
                          @"gradeid":_selectedGradelId,
                         @"tid":_selectedVersonId};   //版本号
    
    [MBProgressHUD showHUD];
    
    [XDHttpTool get:url authCode:[AccountTool shareAccountTool].currentAccount.authCode params:dict success:^(id responseObj) {
        
        [MBProgressHUD hideHUD];
        //NSLog(@"%@",responseObj);
        
        NSDictionary *dictArr = [responseObj objectForKey:@"t"];
        
        NSMutableArray *unitModelArr = [XDUnitCementUnitModel mj_objectArrayWithKeyValuesArray:dictArr];
        self.unitModelArr = unitModelArr;
        
        if(unitModelArr.count == 0){
            [MBProgressHUD showError:@"暂无相关内容,请选择其他课程"];
            return ;
        }
        
        if (status) {       //打开列表
            self.unitArr = self.unitModelArr;
            self.cellOpenStatus = YES;
            [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:UITableViewRowAnimationFade];

        }
        
        
    } failure:^(NSError *error) {
        
        [MBProgressHUD hideHUD];
        [MBProgressHUD showError:XDNetWorkError];
        NSLog(@"%@",error);
    }];
}


#pragma mark - 网络请求
/**
 单元巩固获取老师列表

 @param section 行数
 @param status section展开状态
 */
-(void)getUnitCementTeachersNetWorkRequest:(NSInteger)section selectedStatus:(BOOL)status{
    
    if(!status){                      //关闭列表
        self.teacherArr = nil;
        self.cellOpenStatus = NO;
        [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:UITableViewRowAnimationFade];
        return;
    }
    
    //type = 4 单元巩固  ,type = 5 表示期中期末巩固
    //type 为4时 num传单元id  ; type为5时
    if (_selectedUnitId == 0) {
        [MBProgressHUD showError:@"请选择单元"];
        return;
    }
    NSDictionary *dict = @{@"type":@4,@"num":_selectedUnitId};
    
    NSString *url = BaseURL(@"consolidate.do?action=getTeachers");
    
    
    [MBProgressHUD showHUD];
    [XDHttpTool get:url authCode:[AccountTool shareAccountTool].currentAccount.authCode params:dict success:^(id responseObj) {
        [MBProgressHUD hideHUD];
//        NSLog(@"%@",responseObj);
        NSArray *dictArr = [responseObj objectForKey:@"t"];
        
        NSMutableArray *teacherModelArr = [XDUnitCementTeacherModel mj_objectArrayWithKeyValuesArray:dictArr];
        self.teacherModelArr = teacherModelArr;
        
        
        if(teacherModelArr.count == 0){
            [MBProgressHUD showError:@"暂无相关内容,请选择其他课程"];
            return ;
        }
        
        if (status) {       //打开列表
            
            self.teacherArr = self.teacherModelArr;
            self.cellOpenStatus = YES;
            [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:UITableViewRowAnimationFade];
            
        }
        
    } failure:^(NSError *error) {
        
        [MBProgressHUD hideHUD];
        [MBProgressHUD showError:XDNetWorkError];
        NSLog(@"%@",error);
    }];
    
}



/**
 期中期末巩固获取老师列表
 
 @param section 行数
 @param status section展开状态
 */
-(void)getTermCementTeachersNetWorkRequest:(NSInteger)section selectedStatus:(BOOL)status{
    
    if(!status){                      //关闭列表
        self.teacherArr = nil;
        self.cellOpenStatus = NO;
        [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:UITableViewRowAnimationFade];
        return;
    }
    
    if (_selectedUnitId == 0) {
        [MBProgressHUD showError:@"请选择学期"];
        return;
    }
    NSString *url = BaseURL(@"consolidate.do?action=getTeachers2");
    
    NSDictionary *dict = @{@"gradeId":_selectedGradelId,
                           @"subjectid":_selectedSubjectId,
                            @"termType":_selectedTermId,
                            @"midTerm":_selectedUnitId};    //期中期末巩固 该字段存midTerm
    
    [MBProgressHUD showHUD];
    [XDHttpTool get:url authCode:[AccountTool shareAccountTool].currentAccount.authCode params:dict success:^(id responseObj) {
        [MBProgressHUD hideHUD];
//                NSLog(@"%@",responseObj);
        NSArray *dictArr = [responseObj objectForKey:@"t"];
        
        NSMutableArray *teacherModelArr = [XDUnitCementTeacherModel mj_objectArrayWithKeyValuesArray:dictArr];
        self.teacherModelArr = teacherModelArr;
        
        
        if(teacherModelArr.count == 0){
            [MBProgressHUD showError:@"暂无相关内容,请选择其他课程"];
            return ;
        }
        
        if (status) {       //打开列表
            
            self.teacherArr = self.teacherModelArr;
            self.cellOpenStatus = YES;
            [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:UITableViewRowAnimationFade];
            
        }
        
    } failure:^(NSError *error) {
        
        [MBProgressHUD hideHUD];
        [MBProgressHUD showError:XDNetWorkError];
        NSLog(@"%@",error);
    }];
    
}




/**
 获取单元巩固列表
 */
-(void)getUnitCementListNetWorkRequest{

    if (_selectedUnitId == 0) {
        [MBProgressHUD showError:@"请选择单元"];
        return;
    }
    if (_selectedTeacherId == 0) {
        [MBProgressHUD showError:@"请选择老师"];
        return;
    }
    
    NSString *url = BaseURL(@"consolidate.do?action=getUnitPapers2");
    
    NSDictionary *dict = @{@"uid":[AccountTool shareAccountTool].currentAccount.uid,    //用户id
                        @"unitId":_selectedUnitId,
                        @"teacherId":_selectedTeacherId};
    
    [MBProgressHUD showHUD];
    [XDHttpTool get:url authCode:[AccountTool shareAccountTool].currentAccount.authCode params:dict success:^(id responseObj) {
        
        [MBProgressHUD hideHUD];
        NSLog(@"%@",responseObj);
        
        NSArray *dictArr = [[responseObj objectForKey:@"t"] objectForKey:@"dataList"];
        
        NSMutableArray *unitCementListModelArr = [XDUnitCementListModel mj_objectArrayWithKeyValuesArray:dictArr];
        self.unitCementListModelArr = unitCementListModelArr;
        
        WeakSelf(weakself)
        if(unitCementListModelArr.count!=0){
            //跳转列表
            XDUnitCementListViewController *vc = [[XDUnitCementListViewController alloc]init];
            vc.title = weakself.title;
            vc.unitCementListModelArr = unitCementListModelArr;
            [weakself.navigationController pushViewController:vc animated:YES];
        }else{
            
            [MBProgressHUD showError:XDNetWorkError];
        
        }
        
    } failure:^(NSError *error) {
        [MBProgressHUD hideHUD];
        [MBProgressHUD showError:XDNetWorkError];
        NSLog(@"%@",error);
    }];
    
}

-(void)getTermCementListNetWorkRequest{
    
    if (_selectedUnitId == 0) {
        [MBProgressHUD showError:@"请选择单元"];
        return;
    }
    if (_selectedTeacherId == 0) {
        [MBProgressHUD showError:@"请选择老师"];
        return;
    }
    
    NSString *url = BaseURL(@"consolidate.do?action=getTermPapers2");
    
    NSDictionary *dict = @{@"uid":[AccountTool shareAccountTool].currentAccount.uid,    //用户id
                           @"midTerm":_selectedUnitId,
                           @"teacherId":_selectedTeacherId,
                           @"gradeid":_selectedGradelId,
                           @"subjectid":_selectedSubjectId,
                           @"termId":_selectedTermId,
                           @"tid":_selectedVersonId};
    
    [MBProgressHUD showHUD];
    [XDHttpTool get:url authCode:[AccountTool shareAccountTool].currentAccount.authCode params:dict success:^(id responseObj) {
        
        [MBProgressHUD hideHUD];
        NSLog(@"%@",responseObj);
        
        NSArray *dictArr = [[responseObj objectForKey:@"t"] objectForKey:@"dataList"];
        
        NSMutableArray *unitCementListModelArr = [XDUnitCementListModel mj_objectArrayWithKeyValuesArray:dictArr];
        self.unitCementListModelArr = unitCementListModelArr;
        
        WeakSelf(weakself)
        if(unitCementListModelArr.count!=0){
            //跳转列表
            XDUnitCementListViewController *vc = [[XDUnitCementListViewController alloc]init];
            vc.title = weakself.title;
            vc.unitCementListModelArr = unitCementListModelArr;
            [weakself.navigationController pushViewController:vc animated:YES];
        }else{
            
            [MBProgressHUD showError:XDNetWorkError];
            
        }

        
    } failure:^(NSError *error) {
        
        [MBProgressHUD hideHUD];
        [MBProgressHUD showError:XDNetWorkError];
        NSLog(@"%@",error);
        
    }];
    
    
}


@end
